function requestList() {
  $.ajax({
    url: "http://localhost:8888/api/articles",
    method: "get",
    data: {
      pagenum: 1,
      pagesize: 6,
    },
    success: function (data) {
      load(data);
    },
  });
}
function load(data) {
  $.each(data.data, (index, ele) => {
    let date1 = ele.pub_date.split("T")[0];
    let date2 = ele.pub_date.split("T")[1].split(".")[0];
    let time = +new Date(date1 + " " + date2);
    let diff = (Date.now() - time) / 1000 / 60 / 60 / 24;
    var body = `<div class="item">
          <h4>
            <a href="./detail.html?id=${ele.id}">${ele.title}</a>
          </h4>
          <p class="meta">
            <span>${diff.toFixed(0)}天前 分享至</span>
            <a href="javascript:;" class="wechat"></a>
            <a href="javascript:;" class="weibo"></a>
          </p>
          <p class="brief">${ele.content}</p>
        </div>`;
    $(".kr_news_list").append(body);
  });
}

$(function () {
  requestList();
  let count = 10;
  //加载正在
  let pagesize = Math.floor(Math.random() * 3 + 5);
  $(".kr_more a").on("click", function () {
    $.ajax({
      url: "http://localhost:8888/api/articles",
      method: "get",
      data: {
        pagenum: 1,
        pagesize,
      },
      success: function (data) {
        if (pagesize <= 0) {
          alert("没有更多数据了好么宝贝");
          return;
        }
        load(data);
        pagesize = count - pagesize;
        count = pagesize;
      },
    });
  });
});
